﻿using System;
using System.Collections.Generic;
using System.Text;

namespace 超市系统
{
    internal class SupperMarket
    {
        private Warehouse ck = new Warehouse();

        /// <summary>
        /// 创建超市对象的时候，给仓库的货架上导入货物
        /// </summary>
        public SupperMarket()
        {
            ck.GetPros("ausu", 1000);
            ck.GetPros("banana", 1000);
            ck.GetPros("rice", 1000);
        }

        public void AskBuying()
        {
            Console.WriteLine("欢迎光临，老八土菜馆");
            Console.WriteLine("商品：华硕，香蕉，大米");
            string strType = Console.ReadLine();
            Console.WriteLine("需要多少个");
            int count = Convert.ToInt32(Console.ReadLine());

            //去拿货
            Commodity[] pros = ck.QutPros(strType, count);
            double Money = GetMoney(pros);
            Console.WriteLine("一共{0}元", Money);
            Console.WriteLine("请选择你的打折方式1--不打折 2--打9折 3--满300送100");
            string input = Console.ReadLine();
            CalFather cal = GetCal(input);
            Console.WriteLine("打折后应该付款：{0}元", cal.GetTotalMoney(Money));
            foreach (var item in pros)
            {
                Console.WriteLine("货物名称：{0}，\t货物单价：{1}，\th货物编号：{2}.", item.Name, item.Price, item.Id);
            }
        }

        public CalFather GetCal(string input)
        {
            CalFather cal = null;
            switch (input)
            {
                case "1":
                    cal = new CalNormal();
                    break;

                case "2":
                    cal = new CalRate(0.9);
                    break;

                case "3":
                    cal = new CalMN(300, 100);
                    break;
            }
            return cal;
        }

        public void Show()
        {
            ck.ShowPros();
        }

        /// <summary>
        /// 结算价格
        /// </summary>
        /// <param name="pros"></param>
        /// <returns></returns>
        public double GetMoney(Commodity[] pros)
        {
            double realMoney = 0;
            for (int i = 0; i < pros.Length; i++)
            {
                realMoney += pros[i].Price;
            }
            return realMoney;
        }
    }
}